<?php
$dbhost = 'localhost';  // mysql服务器主机地址
$dbuser = 'ether_gq';            // mysql用户名
$dbpass = '8MN6ZYmayNbRwxm7';          // mysql用户名密码
$dbname = 'ether_gq';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname);

$q = $_GET['q'];
$a='select max(id) from leave_word';
$res=mysqli_query($conn,$a);
$result = mysqli_fetch_array($res);
$result = $result[0];
if($result == 0){
	echo '{"text":"","page":""}';
	return;
};
$result -= intval($q);
$res2 = $result;
$b=0;
 
echo '{"text":[';

for ($i=0; $i<10; $i++)
{   $b=$i;
	$a='SELECT * FROM leave_word where id='.$result;
	$res=mysqli_query($conn,$a);
	$res = mysqli_fetch_array($res);
	echo '{"username":"'.$res[0].'","text":"'.$res[1].'","time":"'.$res[2].'"}';
	
	if ($result==1)
	{
		echo '],"page":[';
		break;	
	};
	$result-=1;

	if ($i==9)
	{
		echo '],"page":[';
	}
	else{
		echo ',';
	};
}
 
if ($q != 0)
{
	echo '"lastPage"';
};

if ($q != 0&&$res2 !== 10&&$b==9){
	echo ',';
};

if ($res2 !== 10&&$b==9){
	echo '"nextPage"';
	};

echo ']}';
?>
